//
//  MyCustomViewController.m
//  didacar
//
//  Created by Yang Yuexia on 15/12/10.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "MyCustomViewController.h"
#import "UIButton+Dzm.h"
#import "SegmentTapView.h"
#import "GuGuLandscapeTableView.h"
#import "MySignUpViewController.h"
#import "MyInitiateViewController.h"
#import "StartCustomMadeViewController.h"
#import "MyCustomViewModel.h"
@interface MyCustomViewController ()<GuGuIndexDelegate,SegmentTapViewDelegate>

@property (nonatomic, strong)  SegmentTapView *segment;
@property (nonatomic , strong) GuGuLandscapeTableView *contentTable;
@property (nonatomic , strong) NSMutableArray *controllers;

@property (weak, nonatomic) IBOutlet UIButton *initiateButton;

- (IBAction)initiateAction:(id)sender;

@property (nonatomic , strong) MyCustomViewModel *myCustomViewModel;

@end

@implementation MyCustomViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的定制";
    
    self.myCustomViewModel = [[MyCustomViewModel alloc ] init];
    
    
    [self.initiateButton style1Button];
    self.initiateButton.backgroundColor = [UIColor orangeColor];
    [self.initiateButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [self initSegmentTapView];
    [self initContentTableView];
    [self setLeftBtnItem];
    
    UIView *panView = [[UIView alloc ] initWithFrame:CGRectMake(0, 0, 30, 568)];
    panView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:panView];
    
    [self loadData];
}

-(void)loadData{
    [self.myCustomViewModel loadCustomData:^(NSInteger resultType, id data, NSString *errorMsg) {
        
    }];
}

// 配置头部视图
-(void)initSegmentTapView{
    self.segment = [[SegmentTapView alloc] initWithFrame:CGRectMake(0, 0 , [UIScreen width] , 44)
                                           withDataArray:@[@"我的报名",@"我的发起"]];
    
    self.segment.delegate = self;
    self.segment.lineWidth = 60;
    [self.view addSubview:self.segment];
}

/**
 * segment点击回调
 */
-(void)selectedIndex:(NSInteger)index{
    [self.contentTable selectIndex:index];
}

-(void)initContentTableView
{
    self.controllers = [[NSMutableArray alloc ] init];
    [self initMySignUpViewController];
    [self initMyInitiateViewController];
    self.contentTable = [[GuGuLandscapeTableView alloc]
                         initWithFrame:CGRectMake(0, 44, [UIScreen width], self.view.frame.size.height - 44-60-64)
                         Array:self.controllers];
    self.contentTable.swipeDelegate = self;
    [self.view addSubview:self.contentTable];
}

// 我的报名
-(void)initMySignUpViewController{
    
    MySignUpViewController *mySignUpViewController = (MySignUpViewController *)[MySignUpViewController getViewControllerFromSbName:@"MyCustom" viewControllerName:@"MySignUpViewController"];
    mySignUpViewController.myCustomViewController  = self;
    [self.controllers addObject:mySignUpViewController];
}

// 我的发起
-(void)initMyInitiateViewController
{
    MyInitiateViewController *myInitiateViewController = (MyInitiateViewController *)[MyInitiateViewController getViewControllerFromSbName:@"MyCustom" viewControllerName:@"MyInitiateViewController"];
    myInitiateViewController.myCustomViewController  = self;
    [self.controllers addObject:myInitiateViewController];
}

-(void)barSelectedIndexChanged:(NSInteger)newIndex{
    [self.segment selectIndex:newIndex];
}

#pragma mark ---- 发起我的上下班线路 ----
- (IBAction)initiateAction:(id)sender
{
    StartCustomMadeViewController*startCustomMade =   (StartCustomMadeViewController *)[StartCustomMadeViewController getViewControllerFromSbName:@"StartCustomMade" viewControllerName:@"StartCustomMadeViewController"];
    startCustomMade.title = @"我的定制";
    [self.navigationController pushViewController:startCustomMade animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
